<template>
  <div>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" width="50" label="序号"></el-table-column>
      <el-table-column prop="hash.ep_ename" label="仪器设备名称" width="250"></el-table-column>
      <el-table-column prop="hash.scale" label="规格型号" width="150"></el-table-column>
      <el-table-column prop="hash.managenum" label="管理编号" width="150"></el-table-column>
      <el-table-column prop="hash.verifiytime" label="本次检定/校准日期" width="100"></el-table-column>
      <el-table-column prop="hash.check_method" label="检查方法" width="100"></el-table-column>
      <el-table-column prop="hash.check_time" label="检查实施日期" width="100"></el-table-column>
      <el-table-column prop="hash.duty_org" label="责任部门" width="150"></el-table-column>
      <el-table-column prop="hash.username" label="核查人员"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="primary"
            @click="checkval(scope.row)"
            v-if="scope.row.hash.status==0"
          >核查结果</el-button>
          <el-button size="mini" type="primary" @click="checkval(scope.row)" v-else>查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="核查结果" :visible.sync="dialogVisible3" width="60%">
      <el-form labelWidth="150px">
        <div class="check-div">
          <span>仪器设备名称：</span>
          <span>{{checkdate[0].hash.ep_ename}}</span>
        </div>
        <div class="check-div">
          <span>规格型号：</span>
          <span>{{checkdate[0].hash.scale}}</span>
        </div>
        <div class="check-div">
          <span>管理编号：</span>
          <span>{{checkdate[0].hash.managenum}}</span>
        </div>
        <div class="check-div">
          <span>本次检定日期：</span>
          <span>{{checkdate[0].hash.verifiytime}}</span>
        </div>
        <div class="check-div">
          <span>检查实施时间：</span>
          <span>{{checkdate[0].hash.check_time}}</span>
        </div>
        <div class="check-div" v-if="ifchecktable==true">
          <span>责任部门：</span>
          <span>{{checkdate[0].hash.duty_org}}</span>
        </div>
        <div class="check-div" v-if="ifchecktable==true">
          <span>检察人员：</span>
          <span>{{checkdate[0].hash.username}}</span>
        </div>
        <el-form-item label="检查方法" class="is-required" style="width:100%">
          <el-input placeholder="请输入" v-model="checkdate2.check_method" :disabled="ifchecktable"></el-input>
          <div class="el-form-item__error" v-if="checkdate2.check_method==''||this.checkdate2.check_method == undefined">
            请输入检查方法
          </div>
        </el-form-item>
        <!-- <el-form-item label="责任部门">
          <selectorg
            :itemorgid="checkdate2.duty_org"
            @getselectorgid="getselectorgid"
            :disabled="ifchecktable"
            style="width:100%;margin-right:10px"
          ></selectorg>
        </el-form-item> -->
        <!-- <el-form-item label="检查人员">
          <searchperson
            @getpersonid="getpersonid"
            style="width:100%;margin-right:10px"
            :itempersonid="checkdate2.username"
            :disabled="ifchecktable"
          ></searchperson>
        </el-form-item> -->
        <el-form-item label="备注" style="width:100%">
          <el-input
            type="textarea"
            :rows="3"
            placeholder="请输入"
            v-model="checkdate2.remark"
            :disabled="ifchecktable"
          ></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer" v-if="ifchecktable==false">
        <el-button size="mini" @click="dialogVisible3 = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="gosurecheck">确 定</el-button>
      </span>
    </el-dialog>
    <el-pagination
      @current-change="handleCurrentChange"
      :currentPage.sync="pagobj.currentPage3"
      :pageSize="pagobj.pagesize"
      layout="total, prev, pager, next"
      :total="pagobj.total"
      style="margin:20px 0;text-align:center"
    ></el-pagination>
  </div>
</template>

<script>
import selectorg from '~/components/common/selectorg.vue';
import searchperson from '~/components/common/searchperson.vue';

export default {
  components: {
    selectorg,
    searchperson,
  },
  data() {
    return {
      itemvalname: {},
      ts: this.newStore(),
      dialogImageUrl: '',
      checkdate: [{ col: '', hash: {} }],
      checkdate2: {
        check_method: '',
      },
      dialogVisible3: false,
      dialogVisible2: false,
      dialogVisible: false,
      branchid: '',
      ifchecktable: false,
    };
  },
  props: {
    tableData: {
      type: Array,
      required: true,
    },
    pagobj: {
      type: Object,
      required: true,
    },
  },
  watch: {
    dialogVisible3() {
      if (this.ifchecktable == false) {
        this.ifchecktable == false;
      }
    },
  },
  methods: {
    gosurecheck() {
      console.log(this.checkdate2.check_method);

      if (this.checkdate2.check_method == '' || this.checkdate2.check_method == undefined) {
        this.$message({
          type: 'error',
          message: ' 请仔细核对填写信息',
        });
        return;
      }
      this.$confirm('是否完成核查结果?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          const req = {
            handle:
              'DD5D108B99FC12B7BAB3E6EAE5C936EF5FBB6F4BAE9BBB730382D6715B544D49',
            id: this.checkdate[0].hash.id,
            duty_org: this.checkdate2.duty_org,
            check_method: this.checkdate2.check_method,
            check_person: this.checkdate2.holder,
            remark: this.checkdate2.remark,
          };
          this.spost(this.ts, '/mainservlet', req).then((ts) => {
            if (ts.d.sflag == 'success') {
              this.$message({
                type: 'success',
                message: '核查成功!',
              });
              this.dialogVisible3 = false;
              this.$parent.getperiolist();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          });
        });
    },
    // 获取负责人
    getpersonid(val) {
      this.checkdate2.holder = val.id;
      this.checkdate2.holders = val.value;
    },
    // 获取部门
    getselectorgid(val) {
      this.checkdate2.duty_org = val;
    },
    checkval(val) {
      // console.log(this.ifchecktable, "09000");
      this.ifchecktable = false;
      this.checkdate2 = {};
      const req = {
        handle:
          'DD5D108B99FC12B7BAB3E6EAE5C936EF5FBB6F4BAE9BBB7323B5E6488CAE7E98',
        eid: val.hash.eid,
        id: val.hash.id,
      };
      this.spost(this.ts, '/mainservlet', req).then((ts) => {
        if (ts.d.sflag == 'success') {
          // console.log(ts.d.data.operation1, "0000000001");

          // this.checkdata=ts.d.data.operation1
          this.checkdate = ts.d.data.operation1;
          this.$parent.getperiolist();
          // this.$emit("itemvals", ts.d.data.operation1);
          // this.branchidlist=ts.d.data.operation1[0],
          // console.log(this.branchidlist.hash.holder,'999');
        }
      });

      if (val.hash.status == 1) {
        this.checkdate2 = val.hash;
        // console.log(this.checkdate2.username, "999999");
        this.ifchecktable = true;
      }
      this.dialogVisible3 = true;
    },
    handleCurrentChange() {
      this.$parent.getperiolist();
    },
    handleSelectionChange(val) {
      this.$emit('update:itemval1', val);
      if (val.length > 0) {
        const req = {
          handle:
            'DD5D108B99FC12B7BAB3E6EAE5C936EF5FBB6F4BAE9BBB7323B5E6488CAE7E98',
          eid: val[0].hash.eid,
          id: val[0].hash.id,
        };
        this.spost(this.ts, '/mainservlet', req).then((ts) => {
          if (ts.d.sflag == 'success') {
            // this.checkdata=ts.d.data.operation1
            this.$emit('itemvals', ts.d.data.operation1);

            // this.branchidlist=ts.d.data.operation1[0],
            // console.log(this.branchidlist.hash.holder,'999');
          }
        });
      }

      // console.log(itemvals,'2');
    },
  },
};
</script>

<style>
.check-div {
  /* text-align: center; */
  padding-left: 80px;
  line-height: 40px;
  font-size: 14px;
}
</style>
